Docker Compose 홈서버 구성

graph TD
    A[사용자] -->|도메인 접속| B(DNS 서버)
    B -->|IP 주소 반환| C(Nginx 컨테이너)
    C -->|요청 분석| D{요청 도메인}
    D -->|leafy.mydomain.com| E[Leafy 컨테이너]
    D -->|ohgnoy.mydomain.com| F[Ohgnoy 컨테이너]
    E -->|DB 연결| G[Leafy DB 컨테이너]
    F -->|DB 연결| H[Ohgnoy DB 컨테이너]
    G -->|데이터| E
    H -->|데이터| F
    E -->|결과 반환| C
    F -->|결과 반환| C
    C -->|웹페이지 반환| A
services:
  # leafy_api 서비스
  leafy_api:
    build:
      context: ./leafy
    container_name: leafy_api
    env_file:
      - ./leafy/.env
    restart: unless-stopped
    networks:
      - web_network
      - internal_db_network

  

  # leafy_db 서비스
  leafy_db:
    image: mysql:8.0
    container_name: leafy_db
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    env_file:
      - ./leafy/.env
    volumes:
      - db_data:/var/lib/mysql
    networks:
      - internal_db_network

  

  # ohgnoy_api 서비스
  ohgnoy_api:
    build:
      context: ./ohgnoy
    container_name: ohgnoy_api
    env_file:
      - ./ohgnoy/.env
    restart: unless-stopped
    volumes:
      - ./ohgnoy:/usr/src/app
    networks:
      - web_network
      - internal_db_network

  

  # ohgnoy_db 서비스
  ohgnoy_db:
    image: mysql:8.0
    container_name: ohgnoy_db
    restart: always
    env_file:
      - ./ohgnoy/.env
    volumes:
      - mysql_data:/var/lib/mysql
    networks:
      - internal_db_network

  

  # code-server 서비스
  code_server:
    image: linuxserver/code-server:latest
    container_name: code_server
    env_file:
      - ./code-server/.env
    volumes:
      - ./config:/config
      - ./projects:/home/coder/projects
    restart: unless-stopped
    networks:
      - web_network

  

  # NGINX 리버스 프록시
  nginx_proxy:
    image: nginx:latest
    container_name: nginx_proxy
    ports:
      - "80:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    depends_on:
      - leafy_api
      - ohgnoy_api
      - code_server
    networks:
      - web_network


volumes:
  db_data:
  mysql_data:

  
networks:
  web_network:
    external: true
  internal_db_network:
    internal: true
graph TD
    %% 외부 요청 시작
    User["👤 사용자"]
    DNSServer["🌐 DNS 서버"]

    User -- "1\. 도메인 접속" --> DNSServer
    DNSServer -- "2\. IP 주소 반환" --> User

    subgraph "💻 Docker Host (Ubuntu Server)"
        Nginx["🚀 Nginx 리버스 프록시"]

        subgraph "🌐 web_network (Docker 내부 통신망)"
            
            subgraph "Leafy 서비스"
                Leafy["🍃 Leafy 컨테이너"]
                LeafyDB[("🐘 Leafy DB 컨테이너")]
            end

            subgraph "Ohgnoy 서비스"
                Ohgnoy["🍊 Ohgnoy 컨테이너"]
                OhgnoyDB[("🐘 Ohgnoy DB 컨테이너")]
            end

            %% 요청 흐름
            Nginx -- "4\. 요청 분석 (leafy...)" --> Leafy
            Nginx -- "4\. 요청 분석 (ohgnoy...)" --> Ohgnoy
            
            Leafy -- "5\. DB 연결" --> LeafyDB
            Ohgnoy -- "5\. DB 연결" --> OhgnoyDB

            %% 데이터 반환 흐름
            LeafyDB -- "6\. 데이터 반환" --> Leafy
            OhgnoyDB -- "6\. 데이터 반환" --> Ohgnoy

            Leafy -- "7\. 결과 반환" --> Nginx
            Ohgnoy -- "7\. 결과 반환" --> Nginx
        end
    end

    %% 최종 응답
    User -- "3\. IP로 서버 접속" --> Nginx
    Nginx -- "8\. 최종 웹페이지 반환" --> User